#ifndef QHOSTFACTORY_H
#define QHOSTFACTORY_H

#include "sharedlibglobal.h"

#include <QMetaObject>
#include <QMap>
#include <QString>

class QAbstractHost;
class XMLObject;

struct tagHostInfo
{
    const QMetaObject *m_host_object;
    QString         m_name;
    QString         m_show_icon;
    QString         m_show_name;
    QString         m_show_group;
    int             m_show_index;
};

class SHAREDLIB_EXPORT QHostFactory
{
public:
    QHostFactory(const QString &name,
                 const QString &show_icon,
                 const QString &show_name,
                 const QString &show_group,
                 int           show_index,
                 const QMetaObject* host);

public:
    static void register_host(const QString &name,
                              const QString &show_icon,
                              const QString &show_name,
                              const QString &show_group,
                              int           show_index,
                              const QMetaObject* host);
    static QAbstractHost* create_host(const QString& name);
    static QList<tagHostInfo*> get_host_info();
    static QAbstractHost* create_host(XMLObject* xml);
    static tagHostInfo *  get_host_info(const QString &name);

    static void sort();
public:
    static QMap<QString,tagHostInfo*>        *m_meta_map;
    static QList<tagHostInfo*>               *m_metas;
};


#ifndef qRegisterHost
    #define qRegisterHost(name,class_name,index) QHostFactory factory_##class_name(\
                                                    name,\
                                                    class_name::get_show_icon(),\
                                                    class_name::get_show_name(),\
                                                    class_name::get_show_group(),\
                                                    index,\
                                                    &class_name::staticMetaObject);
#endif

#endif // QHOSTFACTORY_H
